#include "ScriptGameObject.hpp"
#include "SLB.hpp"
#include "GameWorld.hpp"

using namespace Typhoon;

ScriptGameObject::ScriptGameObject() {
	gameObject = new GameObject();
	gameObject->Data = this;
	if (world) {
		world->AddGameObject(gameObject);
	}
}

ScriptGameObject::~ScriptGameObject() {
	if (world) {
		world->RemoveGameObject(gameObject);
	}
	gameObject->Data = 0;
	delete gameObject;
}

ScriptComponent* ScriptGameObject::AddComponent(ScriptComponent* component) {
	ScriptComponent::IndexToReturn = component->GetId();
	ScriptComponent* copy = gameObject->AddComponent<ScriptComponent>();
	copy->Copy(*component);
	return copy;
}

ScriptComponent* ScriptGameObject::GetComponent(ScriptComponent* component) {
	ScriptComponent::IndexToReturn = component->GetId();
	return gameObject->GetComponent<ScriptComponent>();
}

void ScriptGameObject::RemoveComponent(ScriptComponent* component) {
	ScriptComponent::IndexToReturn = component->GetId();
	return gameObject->RemoveComponent<ScriptComponent>();
}

void ScriptGameObject::InitScripting() {
	SLB::Class<ScriptGameObject>("GameObject")
		.constructor()
		.set("AddComponent", &ScriptGameObject::AddComponent)
		.set("GetComponent", &ScriptGameObject::GetComponent)
		.set("RemoveComponent", &ScriptGameObject::RemoveComponent)
		.set("Debug", &ScriptGameObject::Debug)
		;
}

void ScriptGameObject::SetWorld(GameWorld* world) {
	ScriptGameObject::world = world;
}

GameWorld* ScriptGameObject::world = 0;

void ScriptGameObject::Debug(std::string name) {

}